<?php

namespace App\Helper;

class Ini
{
    public static function parseText($string, $process_sections = FALSE, $scanner_mode = INI_SCANNER_NORMAL)
    {
        return parse_ini_string($string, $process_sections, $scanner_mode);
    }

    public static function parseFile($filename, $process_sections = FALSE)
    {
        return parse_ini_file($filename, $process_sections);
    }

    public static function create(array $array, $process_sections = FALSE)
    {
        $text = '';
        $is2d = is_array(reset($array));
        if ($process_sections && $is2d) //$process_sections == $is2d
        {
            foreach ($array AS $ns => $val)
            {
                $text .= '[' . $ns . ']';
                foreach ($val AS $k => $v)
                {
                    $text .= "$k=$v";
                }
            }
        }
        else
        {

        }

        return $text;
    }

    public static function createFile($f, array $array, $process_sections = FALSE)
    {
        return file_put_contents($f, self::create($array, $process_sections), LOCK_EX);
    }
}